import { controller, get, use } from '../decorator'
import { setRenderData } from '../middleware'
import { news } from '../tplConfig'
import { getDetail } from '../api/news'

@controller('/news(-*)?(.html)?')
export class News {
  @get('/')
  @use(setRenderData)
  home(req, res) {
    const { renderData } = res
    // 多模板配置
    renderData.qqtCustom.tplConfig = news[renderData.qqtData.detail.tplClass]
    res.render('index', renderData)
  }

  @get('/detail/:username/(:id)(.html)?')
  @use(getDetail)
  @use(setRenderData)
  detail(req, res) {
    const { renderData } = res
    const { qqtCustom } = renderData
    res.render(qqtCustom.render, renderData)
  }
}
  